package cn.wit.job.controller;

import cn.wit.job.condition.SearchRecruitInfoCondition;
import cn.wit.utils.pojo.RecruitInfo;
import cn.wit.job.service.RecruitInfoService;
import cn.wit.utils.response.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/job/recruitInfo")
@CrossOrigin
@Api(tags = "招聘信息")
public class RecruitInfoController {
    private Logger logger = LoggerFactory.getLogger(RecruitInfoController.class);

    @Autowired
    private RecruitInfoService recruitInfoService;

    @PostMapping("/insertRecruitInfo")
    @ApiOperation("新增招聘信息")
    public Result insertRecruitInfo(@RequestBody RecruitInfo r){
            return this.recruitInfoService.insert(r);
    }

    @PutMapping("/deleteRecruitInfo/{id}")
    @ApiOperation("删除招聘信息")
    public Result deleteRecruitInfo(@PathVariable("id") int id){
            return this.recruitInfoService.deleteById(id);

    }

    @PutMapping("/updateRecruitInfo")
    @ApiOperation("更新招聘信息")
    public Result updateCompany(@RequestBody RecruitInfo r){
            return this.recruitInfoService.updateById(r);

    }


    @GetMapping("/searchRecruitInfo/{num}/{size}")
    @ApiOperation("分页条件查询招聘信息")
    public Result searchRecruitInfo(@PathVariable("num") int num,
                                       @PathVariable("size") int size,SearchRecruitInfoCondition condition){
        IPage<RecruitInfo> page=new Page<>(num,size);
        try{
            return this.recruitInfoService.searchPage(page, condition);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        return Result.build(500,"error");
    }
}
